﻿package mortal.game.view.changeCareer
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.skill.panel.render.*;
    import mortal.mvc.interfaces.*;

    public class ChangeCareerModule extends BaseWindow
    {
        protected var _rect3d:Rect3DObject;
        private var _img2d:Img2D;
        private var _roleModelPlayer:RoleModelPlayer;
        private var _bg:GImageBitmap;
        private var _btnConfirm:GLoadingButton;
        private var _career1:ChangeCareerItem;
        private var _career2:ChangeCareerItem;
        private var _skillLabel:GImageBitmap;
        private var _skillItems:Array;

        public function ChangeCareerModule(param1:ILayer = null)
        {
            this._skillItems = [];
            super(LayerManager.windowLayer3D);
            this.setSize(650, 555);
            this.title = Language.getString(20707);
            return;
        }// end function

        public function updateCareer(param1:int) : void
        {
            this._skillLabel.imgUrl = "ChangeCareer_YL" + param1;
            this.update3d(param1);
            var _loc_2:* = Cache.instance.role.roleEntityInfo;
            var _loc_3:* = _loc_2.entityInfo.sex;
            if (param1 == ECareer._ECareerWarrior)
            {
                this._career1.updateCareer(2, _loc_3);
                this._career2.updateCareer(4, _loc_3);
            }
            else if (param1 == 2)
            {
                this._career1.updateCareer(1, _loc_3);
                this._career2.updateCareer(4, _loc_3);
            }
            else
            {
                this._career1.updateCareer(1, _loc_3);
                this._career2.updateCareer(2, _loc_3);
            }
            return;
        }// end function

        public function updateSkillList(param1:Array) : void
        {
            var _loc_3:SkillItem = null;
            if (param1 == null)
            {
                return;
            }
            var _loc_2:int = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_3 = this.getSkillItem(_loc_2);
                _loc_3.setSkillInfo(param1[_loc_2] as SkillInfo);
                _loc_2++;
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:GImageBitmap = null;
            var _loc_3:GTextFiled = null;
            super.createDisposedChildrenImpl();
            _loc_1 = UIFactory.gImageBitmap(ImagesConst.ChangeCareer_Bg, 10, 37, null, this.add2d);
            this._bg = _loc_1;
            this._btnConfirm = UIFactory.gLoadingButton(ImagesConst.ChangeCareerConfirmBtn_upSkin, _loc_1.x + 171, _loc_1.y + 308, 142, 50, _contentTopOf3DSprite);
            var _loc_2:* = GlobalStyle.textFormatLv.center();
            _loc_2.size = 10;
            _loc_3 = UIFactory.gTextField(Language.getString(20708), this._btnConfirm.x + 4, this._btnConfirm.y + 23, 142, 20, _contentTopOf3DSprite, _loc_2);
            _loc_3.mouseEnabled = false;
            pushUIToDisposeVec(_loc_3);
            this._career1 = UICompomentPool.getUICompoment(ChangeCareerItem);
            this._career1.x = _loc_1.x + 491;
            this._career1.y = _loc_1.y + 21;
            _contentTopOf3DSprite.addChild(this._career1);
            this._career1.configEventListener(MouseEvent.CLICK, this.clickCareer1);
            this._career2 = UICompomentPool.getUICompoment(ChangeCareerItem);
            this._career2.x = _loc_1.x + 491;
            this._career2.y = _loc_1.y + 236;
            _contentTopOf3DSprite.addChild(this._career2);
            this._career2.configEventListener(MouseEvent.CLICK, this.clickCareer2);
            this._btnConfirm.configEventListener(MouseEvent.CLICK, this.confirmChangeCareer);
            this._skillLabel = UIFactory.gImageBitmap(null, _loc_1.x + 138, _loc_1.y + 357, _contentTopOf3DSprite);
            _loc_2 = GlobalStyle.textFormatLv;
            _loc_2.size = 12;
            _loc_3 = UIFactory.gTextField("", _loc_1.x + 114, _loc_1.y + 458, 500, 70, this, _loc_2);
            _loc_3.multiline = true;
            _loc_3.wordWrap = true;
            _loc_3.mouseEnabled = false;
            _loc_3.htmlText = Language.getString(20709);
            this.updateSkillList(Cache.instance.skill.getLearnedCarrerSkills());
            this.updateCareer(Cache.instance.role.entityInfo.career);
            return;
        }// end function

        private function confirmChangeCareer(event:MouseEvent) : void
        {
            var toCareer:int;
            var selectConfirmHandler:Function;
            var evt:* = event;
            selectConfirmHandler = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    LayerManager.removeAllWindows();
                    GameProxy.role.changeToCareer(toCareer);
                }
                return;
            }// end function
            ;
            if (isDisposed)
            {
                return;
            }
            if (!this._career1.selected && !this._career2.selected)
            {
                MsgManager.showRollTipsMsg(Language.getString(20710));
                return;
            }
            toCareer = this._career1.selected ? (this._career1.career) : (this._career2.career);
            var toName:* = CareerUtil.getCareerName(toCareer);
            Alert.show(Language.getStringByParam(20711, toName), null, Alert.OK | Alert.CANCEL, null, selectConfirmHandler);
            return;
        }// end function

        private function clickCareer1(event:MouseEvent) : void
        {
            this._career1.selected = true;
            this._career2.selected = false;
            this.updateSkillList(Cache.instance.skill.getLearnedCarrerSkills(this._career1.career));
            this.update3d(this._career1.career);
            this._skillLabel.imgUrl = "ChangeCareer_YL" + this._career1.career;
            return;
        }// end function

        private function clickCareer2(event:MouseEvent) : void
        {
            this._career2.selected = true;
            this._career1.selected = false;
            this.updateSkillList(Cache.instance.skill.getLearnedCarrerSkills(this._career2.career));
            this.update3d(this._career2.career);
            this._skillLabel.imgUrl = "ChangeCareer_YL" + this._career2.career;
            return;
        }// end function

        private function getSkillItem(param1:int) : SkillItem
        {
            var _loc_2:SkillItem = null;
            _loc_2 = this._skillItems[param1];
            if (_loc_2 == null)
            {
                _loc_2 = UICompomentPool.getUICompoment(SkillItem);
                _loc_2.setSize(48, 47);
                _loc_2.setBg(ImagesConst.EquipItemBg, 6, 6);
                _loc_2.y = this._bg.y + 398;
                _loc_2.x = this._bg.x + 40 + param1 * 52;
                this._skillItems[param1] = _loc_2;
                _contentTopOf3DSprite.addChild(_loc_2);
            }
            return _loc_2;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._bg = null;
            this._btnConfirm.dispose(param1);
            this._btnConfirm = null;
            this._career1.dispose(param1);
            this._career1 = null;
            this._career2.dispose(param1);
            this._career2 = null;
            this._skillLabel.dispose(param1);
            this._skillLabel = null;
            DisplayUtil.delNotUse(this._skillItems, 0);
            this._skillItems = [];
            this.remove3d();
            return;
        }// end function

        private function add2d() : void
        {
            if (this._rect3d == null)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(this._bg.x, this._bg.y, 640, 462), this);
            }
            this._img2d = new Img2D(null, this._bg.bitmapData, new Rectangle(0, 0, 640, 462), false);
            this._rect3d.addImg(this._img2d);
            return;
        }// end function

        private function update3d(param1:int) : void
        {
            var _loc_2:* = Cache.instance.role.roleEntityInfo;
            var _loc_3:* = _loc_2.entityInfo.sex;
            var _loc_4:* = _loc_2.clothes;
            var _loc_5:* = _loc_2.weapon;
            var _loc_6:* = _loc_2.hair;
            var _loc_7:* = _loc_2.wing;
            var _loc_8:* = _loc_2.entityInfo.VIP;
            var _loc_9:* = Cache.instance.fashion.getFashionHideState(EFashionType._EFashionClothes);
            var _loc_10:* = _loc_9 == EFashionStatus._EFashionStatusHide ? (true) : (false);
            if (_loc_10)
            {
                _loc_4 = 0;
            }
            if (this._rect3d == null)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(this._bg.x, this._bg.y, 640, 462), this);
            }
            if (this._roleModelPlayer == null)
            {
                this._roleModelPlayer = FrObjectPool.getObject(RoleModelPlayer, this);
            }
            this._roleModelPlayer.updateInfo(param1, _loc_3, _loc_4, _loc_5, _loc_6, _loc_7, _loc_8);
            this._roleModelPlayer.scaleAll = 2.2;
            this._roleModelPlayer.setRenderList(this._rect3d.renderList);
            this._roleModelPlayer.useLight();
            this._roleModelPlayer.rotationY = 0;
            this._rect3d.addObject3d(this._roleModelPlayer, 243, 300);
            return;
        }// end function

        private function remove3d() : void
        {
            if (this._rect3d)
            {
                if (this._img2d)
                {
                    this._rect3d.removeImg(this._img2d);
                    this._img2d = null;
                }
                this._rect3d.disposeObj3d(this._roleModelPlayer);
                this._roleModelPlayer = null;
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            return;
        }// end function

    }
}
